package com.teacold.customdemo.recyclerdemo;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.teacold.customdemo.R;

import java.util.ArrayList;

import androidx.recyclerview.widget.RecyclerView;

public class DiuffUtilsAdapter extends RecyclerView.Adapter<DiuffUtilsAdapter.DiffUtilsViewHolder> {
    private ArrayList<RecyclerBean> mData;
    private Context mContext;


    @Override
    public DiffUtilsViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view=LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_item,null);
        return new DiffUtilsViewHolder(view);
    }

    public ArrayList<RecyclerBean> getmData() {
        return mData;
    }

    public void setmData(ArrayList<RecyclerBean> mData) {
        this.mData = new ArrayList<>(mData);
    }

    @Override
    public void onBindViewHolder(DiffUtilsViewHolder holder, int position) {
           holder.item_id.setText(mData.get(position).getmId());
           holder.item_name.setText(mData.get(position).getmName());
    }

    @Override
    public int getItemCount() {
        return mData==null?0:mData.size();
    }

    public class DiffUtilsViewHolder extends RecyclerView.ViewHolder {
        TextView item_id,item_name;

        public DiffUtilsViewHolder(View itemView) {
            super(itemView);
            item_id=itemView.findViewById(R.id.item_id);
            item_name=itemView.findViewById(R.id.item_name);
        }
    }
}
